<%@attribute name="query" type="java.lang.String" required="true" %>
<%@ tag import="java.sql.*,java.util.*" %>
<%@ variable name-given="data" variable-class="java.util.List" scope="AT_BEGIN" %>
<%!
    List<String> queryDatabase(String query) {
        List<String> list = new ArrayList<String>();
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            String url = "jdbc:mysql://localhost:3306/ShopSystem?useSSL=false&serverTimezone=UTC";
            String user = "sa";
            String password = "";
            Connection conn = DriverManager.getConnection(url, user, password);
            Statement stmt = conn.createStatement();
            ResultSet rs = stmt.executeQuery(query);
            while (rs.next())
                list.add(rs.getString(1));
        } catch (Exception e) {
            list.add(e.getMessage());
        }
        return list;
    }
%>
<%
    jspContext.setAttribute("words", queryDatabase(query));
%>